package cn.iocoder.yudao.module.vlog.info.controller.app;

import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import cn.iocoder.yudao.module.vlog.info.service.VLogInfoService;
import cn.iocoder.yudao.module.vlog.info.vo.AppVLogActionReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 视频收藏")
@RestController
@RequestMapping("/vlog/favorite")
@Validated
public class AppVLogFavoriteController {

    @Resource
    private VLogInfoService vLogInfoService;
    @Resource
    private MemberUserApi memberUserApi;


    @PostMapping("/create")
    @Operation(summary = "视频收藏")
    public CommonResult<Boolean> collect(@Valid @RequestBody AppVLogActionReqVO reqVO) {
        vLogInfoService.collectVLog(getLoginUserId(), reqVO.getVlogId());
        return success(true);
    }

    @PostMapping("/cancel")
    @Operation(summary = "取消视频收藏")
    public CommonResult<Boolean> uncollect(@Valid @RequestBody AppVLogActionReqVO reqVO) {
        vLogInfoService.uncollectVLog(getLoginUserId(), reqVO.getVlogId());
        return success(true);
    }

    @GetMapping("/list-user")
    @Operation(summary = "获得视频收藏的用户列表")
    @Parameter(name = "vlogId", description = "视频编号", required = true)
    public CommonResult<List<UserSimpleVO>> getUserList(Long vlogId) {
        List<Long> userIds = vLogInfoService.getVLogCollectUserIds(vlogId);
        return success(memberUserApi.getUserSimpleList(userIds));
    }

}
